﻿using BasicData.Application.Input;
using BasicData.Application.Input.Customer;
using BasicData.Application.Output;
using BasicData.Application.Services.Customer;
using BasicData.Result;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BasicData.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    ///<summary>
    /// 客户管理
    /// </summary>
    public class CustomerController : ControllerBase
    {
        ICustomerServices services;
        ILogger<CustomerController> logger;

        public CustomerController(ICustomerServices services, ILogger<CustomerController> logger)
        {
            this.services = services;
            this.logger = logger;
        }
        /// <summary>
        /// 添加客户
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<int> AddCustomer(CustomerInput input)
        {
            logger.LogInformation("添加客户");
          return services.AddCustomer(input);
        }
        /// <summary>
        /// 删除客户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut]
        public ApiResult<int> DeleteCustomer(long id)
        {
            logger.LogInformation("删除客户");
            return services.DeleteCustomer(id);
        }
        /// <summary>
        /// 获取客户列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiPaging<CustomerOutPut> GetCustomer([FromQuery]PageInput input)
        {
            logger.LogInformation("获取客户列表");
            return services.GetCustomer(input);
        }
        /// <summary>
        /// 更新客户
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public ApiResult<int> UpdateCustomer(UpdateCustomerInput input)
        {
            logger.LogInformation("更新客户");
            return services.UpdateCustomer(input);
        }
    }
}
